package site.jlopen.controller.modules;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import site.jlopen.assets.config.ThreadAuthUser;
import site.jlopen.domain.datasource.event.KusciaDatasourceEvent;
import site.jlopen.domain.datasource.event.KusciaDatasourceNodeEvent;
import site.jlopen.domain.node.event.KusciaNodeEvent;
import site.jlopen.entity.BaseResponse;
import site.jlopen.entity.req.DatasourceReq;
import site.jlopen.service.BaseService;

@RestController
@RequestMapping("/dataSource")
public class DataSourceController extends BaseService {

	@PostMapping("/create")
	public BaseResponse<String> create(@RequestBody DatasourceReq req) {
		return dataSourceService.createDataSource(ThreadAuthUser.id(), req);
	}

	@GetMapping("/list")
	public List<KusciaDatasourceEvent> list() {
		return dataSourceService.list(ThreadAuthUser.id());
	}

	@GetMapping("/nodes")
	public List<KusciaDatasourceNodeEvent> nodes(Long dsId) {
		return nodeService.listByDsId(dsId);
	}

	@GetMapping("/nodesNotDs")
	public List<KusciaNodeEvent> nodesNotDs() {
		return nodeService.listByNotDs(ThreadAuthUser.id());
	}

	@GetMapping("/remove")
	public BaseResponse<String> remove(Long dataSourceId) {
		return dataSourceService.remove(dataSourceId);
	}

	@GetMapping("/info")
	public BaseResponse<KusciaDatasourceEvent> info(Long dataSourceId) {
		return dataSourceService.getDataSource(dataSourceId);
	}

	@GetMapping("/restatus")
	public BaseResponse<String> restatus(Long dataSourceId, Long nodeId) {
		return dataSourceService.restatus(dataSourceId, nodeId);
	}

	@PostMapping("/bindNode")
	public BaseResponse<String> bindNode(Long dataSourceId, Long nodeId) {
		return dataSourceService.bindNode(dataSourceId, nodeId);
	}

	@GetMapping("/unBindNode")
	public BaseResponse<String> unBindNode(Long dataSourceId, Long nodeId) {
		return dataSourceService.unBindNode(dataSourceId, nodeId);
	}
}
